#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 510;
int a[N][N], b[N][N];
void shun(int x, int y, int r)
{
	for (int i = x - r; i <= x + r; i++)
		for (int j = y - r; j <= y + r; j++)
			b[i][j] = a[i][j];

	int x1 = x + r;
	int y1 = y - r;
	for (int i = x - r; i <= x + r; i++)
	{
		for (int j = y - r; j <= y + r; j++)
		{
			a[i][j] = b[x1][y1];
			x1--;
		}
		x1 = x + r;
		y1++;
	}
}
void ni(int x, int y, int r)
{
	for (int i = x - r; i <= x + r; i++)
		for (int j = y - r; j <= y + r; j++)
			b[i][j] = a[i][j];
	
	int x1 = x - r;
	int y1 = y + r;
	for (int i = x - r; i <= x + r; i++)
	{
		for (int j = y - r; j <= y + r; j++)
		{
			a[i][j] = b[x1][y1];
			x1++;
		}
		x1 = x - r;
		y1--;
	}
}
int main()
{
	int n, m;
	cin >> n >> m;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cnt++;
			a[i][j] = cnt;
		}
	}
	while (m--)
	{
		int x, y, r, z;
		cin >> x >> y >> r >> z;
		if (z == 0)
			shun(x,y,r);
		else if (z == 1)
			ni(x,y,r);
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}